<include file="SpStore:header" />
		<!----《/头部结束》----->
		<div class="ncsc-layout wrapper">
<include file="SpStore:activity_left" />

  <div id="layoutRight" class="ncsc-layout-right">
    <div class="ncsc-path"><i class="icon-desktop"></i>商家管理中心<i class="icon-angle-right"></i>促销<i class="icon-angle-right"></i>限时折扣</div>
    <div class="main-content" id="mainContent">
      <script type="text/javascript" src="__PUBLIC__/Home/js/template.min.js" charset="utf-8"></script>
<script type="text/javascript">
    $(document).ready(function(){

        // 当前编辑对象，默认为空
        $edit_item = {};

        //现实商品搜索
        $('#btn_show_goods_select').on('click', function() {
            $('#div_goods_select').show();
        });

        //隐藏商品搜索
        $('#btn_hide_goods_select').on('click', function() {
            $('#div_goods_select').hide();
        });

        //搜索商品
        $('#btn_search_goods').on('click', function() {
            var url = "/store/search_goods.html?";
            url += $.param({goods_name: $('#search_goods_name').val()});
			//alert(url);
            $('#div_goods_search_result').load(url);
        });
		//关闭窗口
		 $('.dialog_close_button').live('click', function() {
			//alert(11);
            $('#dialog_add_xianshi_goods').hide();
        });
		
        $('#div_goods_search_result').on('click', 'a.demo', function() {
            $('#div_goods_search_result').load($(this).attr('href'));
            return false;
        });

        //添加限时折扣商品弹出窗口 
        $('#div_goods_search_result').on('click', '[nctype="btn_add_xianshi_goods"]', function() {
            $('#dialog_goods_id').val($(this).attr('data-goods-id'));
            $('#dialog_goods_name').text($(this).attr('data-goods-name'));
            $('#dialog_goods_price').text($(this).attr('data-goods-price'));
            $('#dialog_input_goods_price').val($(this).attr('data-goods-price'));
            $('#dialog_goods_img').attr('src', $(this).attr('data-goods-img'));
            $('#dialog_add_xianshi_goods').nc_show_dialog({width: 450, title: '添加商品'});
            $('#dialog_xianshi_price').val('');
            $('#dialog_add_xianshi_goods_error').hide();
        });

        //添加限时折扣商品
        $('#btn_submit').live('click', function() {
            var goods_id = $('#dialog_goods_id').val();
            var xianshi_id = '{$xianshi.xianshi_id}';
			
            var goods_price = Number($('#dialog_input_goods_price').val());
            var xianshi_price = Number($('#dialog_xianshi_price').val());
			
            if(!isNaN(xianshi_price) && xianshi_price > 0 && xianshi_price < goods_price) {
						
				$.ajax({
					url:"{:U('store/xianshi_goods_add')}",
					data:{goods_id: goods_id, xianshi_id: xianshi_id, xianshi_price: xianshi_price, type:'xianshi_goods_add'},
					type:'post',
					dataType:'json',
					success:function (e) {					
						if(e.result){
						
							$('#dialog_add_xianshi_goods').hide();
							
							alert(e.result); 
							$('#xianshi_goods_list_norecord').hide();
							$('#xianshi_goods_list').prepend(template.render('xianshi_goods_list_template', data.xianshi_goods)).hide().fadeIn('slow');				
						 
						} else {
						
							alert(e.message); 
				
						}
				
					}
				});
            } else {
                $('#dialog_add_xianshi_goods_error').show();
            }
        });

        //编辑限时活动商品
        $('#xianshi_goods_list').on('click', '[nctype="btn_edit_xianshi_goods"]', function() {
            $edit_item = $(this).parents('tr.bd-line');
            var xianshi_goods_id = $(this).attr('data-xianshi-goods-id');
            var xianshi_price = $edit_item.find('[nctype="xianshi_price"]').text();
            var goods_price = $(this).attr('data-goods-price');
            $('#dialog_xianshi_goods_id').val(xianshi_goods_id);
            $('#dialog_edit_goods_price').text(goods_price);
            $('#dialog_edit_xianshi_price').val(xianshi_price);
            $('#dialog_edit_xianshi_goods').nc_show_dialog({width: 450, title: '修改价格'});
        });

        $('#btn_edit_xianshi_goods_submit').on('click', function() {
            var xianshi_goods_id = $('#dialog_xianshi_goods_id').val();
            var xianshi_price = Number($('#dialog_edit_xianshi_price').val());
            var goods_price = Number($('#dialog_edit_goods_price').text());
            if(!isNaN(xianshi_price) && xianshi_price > 0 && xianshi_price < goods_price) {
                $.post('',
                    {xianshi_goods_id: xianshi_goods_id, xianshi_price: xianshi_price},
                    function(data) {
                        if(data.result) {
                            $edit_item.find('[nctype="xianshi_price"]').text(data.xianshi_price);
                            $edit_item.find('[nctype="xianshi_discount"]').text(data.xianshi_discount);
                            $('#dialog_edit_xianshi_goods').hide();
                        } else {
                            showError(data.message);
                        }
                    }, 'json'
                ); 
            } else {
                $('#dialog_edit_xianshi_goods_error').show();
            }
        });

        //删除限时活动商品
        $('#xianshi_goods_list').on('click', '[nctype="btn_del_xianshi_goods"]', function() {
            var $this = $(this);
            if(confirm('确认删除？')) {
                var xianshi_goods_id = $(this).attr('data-xianshi-goods-id');
                $.post('',
                    {xianshi_goods_id: xianshi_goods_id},
                    function(data) {
                        if(data.result) {
                            $this.parents('tr').hide('slow', function() {
                                var xianshi_goods_count = $('#xianshi_goods_list').find('.bd-line:visible').length;
                                if(xianshi_goods_count <= 0) {
                                    $('#xianshi_goods_list_norecord').show();
                                }
                            });
                        } else {
                            showError(data.message);
                        }
                    }, 'json'
                );
            }
        });

        //渲染限时折扣商品列表
        xianshi_goods_array = $.parseJSON('[{"xianshi_goods_id":"26","xianshi_id":"8","xianshi_name":"sssss","xianshi_title":"sssss","xianshi_explain":"","goods_id":"237","store_id":"177","goods_name":"\u4e2d\u79d1\u6a80\u9999\u4ea7\u54c1\u4e4b\u4f5b\u73e0\uff08\u8001\u5c71\u9999\uff09 \u7ea2\u8272 ss","goods_price":"150.00","xianshi_price":"100.00","goods_image":"1_04418254218437108.jpg","start_time":"1492755240","end_time":"1493481600","lower_limit":"1","state":"1","xianshi_recommend":"0","gc_id_1":"0","goods_url":"http:\/\/www.hao123.top\/shop\/index.php?act=goods&op=index&goods_id=237","image_url":"http:\/\/www.hao123.top\/data\/upload\/shop\/common\/default_goods_image_60.gif","xianshi_discount":"6.7\u6298"}]');
        if(xianshi_goods_array.length > 0) {
            var xianshi_goods_list = '';
            $.each(xianshi_goods_array, function(index, xianshi_goods) {
                xianshi_goods_list += template.render('xianshi_goods_list_template', xianshi_goods);
            });
            $('#xianshi_goods_list').prepend(xianshi_goods_list);
        } else {
            $('#xianshi_goods_list_norecord').show();
        }
    });
</script>
<div class="tabmenu">
    <ul class="tab pngFix">
  <li class="normal"><a href="/store/shop_xianshi.html">商城活动</a></li><li class="active"><li class="normal"><a href="/store/st_xianshi.html">我参与的活动</a></li><li class="active"><a href="index.php?act=store_promotion_xianshi&amp;op=xianshi_manage&amp;xianshi_id=8">商品管理</a></li></ul>
        <a id="btn_show_goods_select" class="ncsc-btn ncsc-btn-green" href="javascript:;"><i></i>添加商品</a> </div>
    <table class="ncsc-default-table">
  <tbody>
    <tr>
      <td class="w90 tr"><strong>活动名称：</strong></td>
      <td class="w120 tl">{$xianshi.xianshi_name}</td>
      <td class="w90 tr"><strong>开始时间：</strong></td>
      <td class="w120 tl">{$xianshi.start_time|=date('Y-m-d',###)}</td>
      <td class="w90 tr"><strong>结束时间：</strong></td>
      <td class="w120 tl">{$xianshi.end_time|=date('Y-m-d',###)}</td>
      <td class="w90 tr"><strong>购买下限：</strong></td>
      <td class="w120 tl">		  
		  <if condition="$xianshi.lower_limit eq '0'" > 
		  不限
		  <else/>
		  {$xianshi.lower_limit}
		  </if>
	 </td>
      <td class="w90 tr"><strong>状态：</strong></td>
      <td class="w120 tl">
		  <in name="xianshi.state" value="0"> 
		  管理员关闭
		  </in>
		  <in name="xianshi.state" value="1"> 
		  正常
		  </in>	  
	  </td>
    </tr>
</tbody></table>
<div class="alert">
  <strong>说明：</strong>
  <ul>
    <li>1、限时折扣商品的时间段不能重叠</li>
    <li>2、点击添加商品按钮可以搜索并添加参加活动的商品，点击删除按钮可以删除该商品</li>
  </ul>
</div>
<!-- 商品搜索 -->
<div id="div_goods_select" class="div-goods-select" style="display: none;">
    <table class="search-form">
      <tbody>
		  <tr>
			<th class="w150"><strong>第一步：搜索店内商品</strong></th>
			<td class="w160">
				<input id="search_goods_name" type="text w150" class="text" name="goods_name" value="">
			</td>		  
			<td class="w70 tc">
				<a href="javascript:void(0);" id="btn_search_goods" class="ncsc-btn"><i class="icon-search"></i>搜索</a>
			</td>
			<td class="w10"></td>
			<td>
				<p class="hint">不输入名称直接搜索将显示店内所有普通商品，特殊商品不能参加。</p>
			</td>
		  </tr>
    </tbody>
  </table>
  
	<div id="div_goods_search_result" class="search-result"></div> 
  
  
  <a id="btn_hide_goods_select" class="close" href="javascript:void(0);">X</a> </div>
  
<table class="ncsc-default-table">
  <thead>
    <tr>
      <th class="w10"></th>
      <th class="w50"></th>
      <th class="tl">商品名称</th>
      <th class="w90">商品价格</th>
      <th class="w120">折扣价格</th>
      <th class="w120">折扣率</th>
      <th class="w120">操作</th>
    </tr>
  </thead>
  
  <tbody id="xianshi_goods_list">
	<foreach name="xs_list" item="vo">
	  <tr class="bd-line">
		<td></td>
		<td><div class="pic-thumb"><a href="{:U('shop/goods')}?gid={$vo.goods_id}" target="_blank"><img src="{$vo.goods_image}" alt=""></a></div></td>
		<td class="tl"><dl class="goods-name"><dt><a href="{:U('shop/goods')}?gid={$vo.goods_id}" target="_blank">{$vo.goods_name}</a></dt></dl></td>
		<td>¥{$vo.goods_price}</td>
		<td>¥<span nctype="xianshi_price">{$vo.xianshi_price}</span></td>
		<td><span nctype="xianshi_discount">{$vo.xianshi_discount}折</span></td>
		<td class="nscs-table-handle">
			<span><a nctype="btn_edit_xianshi_goods" class="btn-blue" data-xianshi-goods-id="26" data-goods-price="150.00" href="javascript:void(0);"><i class="icon-edit"></i><p>编辑</p></a></span>
			<span><a nctype="btn_del_xianshi_goods" class="btn-red" data-xianshi-goods-id="26" href="javascript:void(0);"><i class="icon-trash"></i><p>删除</p></a></span>
			</td>
	 </tr>
	</foreach>
    <tr id="xianshi_goods_list_norecord" style="display:none">
      <td class="norecord" colspan="20"><div class="warning-option"><i class="icon-warning-sign"></i><span>暂无符合条件的数据记录</span></div></td>
    </tr>
  </tbody>
  
</table>
<div class="bottom">
  <label class="submit-border"><input type="submit" class="submit" id="submit_back" value="返回活动列表" onclick="window.location='/store/st_xianshi.html'"></label>
</div>


    </div>
  </div>
</div>
			<!--底部-->

<include file="SpStore:footer" />
	</body>

</html>